import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class userinterface extends JFrame implements MouseListener {

	static JPanel mainPanel;
	static int n = -1, m = -1, k = -1;
	static JButton b1, b2, b3;
	static JTextArea j1, j2, j3;
	static JTextArea output;
	static JScrollPane sp;

	public userinterface() {
		super("UNICORNS");
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setSize(400, 550);
		mainPanel = new JPanel();
		mainPanel.setLayout(null);
		mainPanel.setBounds(0, 0, 750, 550);
		JLabel t = new JLabel("Unicorn Simulator !! Welcome");
		t.setVisible(true);
		t.setLocation(0, 0);
		t.setSize(300, 30);
		JLabel t1 = new JLabel("Please enter the value of n");
		t1.setVisible(true);
		t1.setLocation(0, 30);
		t1.setSize(300, 30);
		JLabel t2 = new JLabel("Please enter the value of m");
		t2.setVisible(true);
		t2.setLocation(0, 130);
		t2.setSize(300, 30);
		JLabel t3 = new JLabel("Please enter the value of k");
		t3.setVisible(true);
		t3.setLocation(0, 230);
		t3.setSize(300, 30);
		j1 = new JTextArea();
		j1.setVisible(true);
		j1.setSize(40, 20);
		j1.setLocation(0, 50);
		j2 = new JTextArea();
		j2.setVisible(true);
		j2.setSize(40, 20);
		j2.setLocation(0, 150);
		j3 = new JTextArea();
		j3.setVisible(true);
		j3.setSize(40, 20);
		j3.setLocation(0, 250);
		sp = new JScrollPane(output);
		b1 = new JButton();
		b1.setText("OK");
		b1.setVisible(true);
		b1.setSize(75, 50);
		b1.setLocation(200, 50);
		b1.addMouseListener(this);
		b2 = new JButton();
		b2.setText("OK");
		b2.setVisible(true);
		b2.setSize(75, 50);
		b2.setLocation(200, 150);
		b2.addMouseListener(this);
		b3 = new JButton();
		b3.setText("OK");
		b3.setVisible(true);
		b3.setSize(75, 50);
		b3.setLocation(200, 250);
		b3.addMouseListener(this);
		mainPanel.add(b1);
		mainPanel.add(b2);
		mainPanel.add(b3);
		mainPanel.add(t);
		mainPanel.add(t1);
		mainPanel.add(t2);
		mainPanel.add(t3);
		mainPanel.add(j1);
		mainPanel.add(j2);
		mainPanel.add(j3);
		this.setContentPane(mainPanel);
		this.validate();
		this.setVisible(true);

	}

	public static void main(String[] args) {
		new userinterface();
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		Object clicked = arg0.getSource();
		JButton c = (JButton) clicked;
		if (c.equals(b1)) {
			n = Integer.parseInt(j1.getText());
		} else {
			if (c.equals(b2)) {
				m = Integer.parseInt(j2.getText());
			} else {
				if (c.equals(b3)) {
					k = Integer.parseInt(j3.getText());
				}
			}
		}
		if (n != -1 && m != -1 && k != -1) {
			Unicorns u = new Unicorns();
			JFrame newf = new JFrame();
			JPanel newp = new JPanel();
			newf.setSize(300, 300);
			newp.setLayout(new BorderLayout());
			newp.setBounds(0, 0, 300, 300);
			output = new JTextArea();
			output.setVisible(true);
			output.setSize(300, 300);
			output.setLocation(290, 30);
			sp = new JScrollPane(output);
			newp.add(sp, BorderLayout.CENTER);
			newf.setContentPane(newp);
			newf.setTitle("Output");
			newf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			newf.pack();
			newf.setVisible(true);
			u.run(n, m, k);
			u.ui = this;

		}

	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

}
